package com.task.web.controller.core;

import com.task.common.annotation.Log;
import com.task.common.core.controller.BaseController;
import com.task.common.core.domain.AjaxResult;
import com.task.common.core.page.TableDataInfo;
import com.task.common.enums.BusinessType;
import com.task.common.utils.SecurityUtils;
import com.task.core.dto.request.DataPromptRequestDTO;
import com.task.core.service.CheckService;
import com.task.core.service.DataPromptService;
import com.task.core.vo.resp.DataPromptDetailRespVo;
import com.task.core.vo.resp.DatasourceDetailRespVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 提示语表控制层
 *
 */
@RestController
@RequestMapping("/dataPrompt")
public class DataPromptController extends BaseController {
    @Resource
    private DataPromptService dataPromptService;

    @Resource
    private CheckService checkService;

    @Log(title = "数据提示语管理", businessType = BusinessType.INSERT)
    @PostMapping("/addPrompt")
    public AjaxResult addPrompt(@RequestBody DataPromptRequestDTO request) {
        dataPromptService.addPrompt(request);
        return success();
    }

    @GetMapping("/getPromptForOption")
    @PreAuthorize("@ss.hasPermi('tipsManage:option')")
    public TableDataInfo getPromptForOption(DataPromptRequestDTO request){
        return getDataTable(dataPromptService.getPromptForOption(request));
    }


    @PutMapping("/modifyPrompt")
    @Log(title = "数据提示语管理", businessType = BusinessType.UPDATE)
    public AjaxResult modifyPrompt(@RequestBody DataPromptRequestDTO request){
        checkService.check("data_prompt_info", request.getCode());
        request.setOperationBy(SecurityUtils.getLoginUser().getUserId());
        dataPromptService.modifyPrompt(request);
        return success();
    }

    @DeleteMapping("/deletePrompt/{promptCode}")
    @Log(title = "数据提示语管理", businessType = BusinessType.DELETE)
    public AjaxResult deletePrompt(@PathVariable String promptCode){
        checkService.check("data_prompt_info", promptCode);
        dataPromptService.deletePrompt(promptCode,
                SecurityUtils.getLoginUser().getUserId());
        return success();
    }
    @GetMapping("/getPromptByPage")
    @PreAuthorize("@ss.hasPermi('tipsManage:list')")
    public TableDataInfo getPromptByPage(DataPromptRequestDTO request){
        startPage(request.getPageNum(),request.getPageSize());
        return getDataTable(dataPromptService.getPromptByPage(request));
    }

    @GetMapping ("/getPromptDetail/{promptCode}")
    @PreAuthorize("@ss.hasPermi('system:prompt:edit')")
    public AjaxResult getPromptDetail(@PathVariable String promptCode) {
        checkService.check("data_prompt_info", promptCode);
        DataPromptDetailRespVo dataPromptDetailRespVo = dataPromptService.getPromptDetail(promptCode);
        return success(dataPromptDetailRespVo);
    }

}

